﻿using System;
using System.Linq;
using System.Reflection;
using NUnit.Framework;

namespace Birkelund.QueryStrings.Test.ArchitectureTests
{
    public class AccessModifierTest
    {
        [Test]
        public void EncureInternalNamespaceDoesNotContainPublicTypes()
        {
            const string @namespace = "Birkelund.QueryStrings.Internals";
            Assembly asm = Assembly.GetAssembly(typeof(FailureReason));

            Type[] typesInNamespace = asm.GetTypes()
                .Where(x => x.Namespace == @namespace)
                .ToArray();
            Assert.AreNotEqual(0, typesInNamespace.Length, "There are no types at all in the namespace " + @namespace);


            string[] typesWhichArePublic = typesInNamespace
                .Where(x => x.IsPublic)
                .Select(x=> x.FullName)
                .ToArray();
            Assert.AreEqual(0, typesWhichArePublic.Length, "These public types are not valid in the namespace '{0}' types: {1}{2}", 
                @namespace, 
                Environment.NewLine, 
                string.Join(Environment.NewLine, typesWhichArePublic));
        }
    }
}
